<?php

require_once('mysql.php');

class PhotoAlbum{

	var $id;
	var $nom;
	var $path;
	var $description;
	var $timestamp;
	var $bdd;
	
	function PhotoAlbum($Id,$Nom,$Path,$Description,$Timestamp,$Bdd){
		$this->id = $Id;
		$this->nom = $Nom;
		$this->path = $Path;
		$this->description = $Description;
		$this->timestamp = $Timestamp;
		$this->bdd = $Bdd;
	}
	
	function displayOverview(){
		//recuperer les adresses de miniatures (5 miniatures pour l'apercu)
		$miniatures;
		
		?>
		<div class="album_photo">
			<h4><?php echo '<a href="index.php?page=photos&album_id='.$this->id.'">'.$this->nom.'</a>';?></h4>
			<?php echo "ajout� le ".date('d/m/Y � H\hi', $this->timestamp); ?>
			<br/><br/>
			<p><?php echo $this->description;?></p>
		</div>
		<?php
	}
	
	function displayThumbnails(){
		$page_photos;
		if (isset($_GET['aff']))
			$page_photos = $_GET['aff'];
		else 
			$page_photos = 1;
		?>
		<div class="album_photo">
			<h4><?php echo '<a href="index.php?page=photos&album_id='.$this->id.'">'.$this->nom.'</a>';?></h4>
			<?php echo "ajout� le ".date('d/m/Y � H\hi', $this->timestamp); ?>
			<br/>
			<p><?php echo $this->description;?></p>
			<table>
				<tr>
		<?php
			//contient les noms de fichiers images
			$imagesFilesName = $this->scanDirectory($this->path);
			$i=0;
			while($i<24 || sizeof($imagesFilmesName) == 0){
			
				$elt = array_shift($imagesFilesName);
				if ($elt != ''){
					$dir_name = array_pop(explode('/',$this->path));
					$elt = "photos/".$dir_name."/".$elt;
					echo "<td><a href='".$elt."' rel='lightbox[".$dir_name."]' ><img src='".$elt."' width='147' height='110' alt='' /></a></td>";
				}
				if (($i+1)%4==0 && $i!=0)
					echo "</tr><tr>";
			}
		?>
			</tr>
			</table>
			
		<?php
			if (sizeof($imagesFilesName) > 0){
				echo "<a href='index.php?page=photos&album_id=".$_GET['album_id']."&aff=".$pages_photos++."'>Suivant >></a>";
			}
			
		?>
		</div>
		<?php
	}
	
	//retourne un tableau avec les chemins absolus des fichiers images de l'album
	function scanDirectory($directory){
		
		$pathes = array();
		$Mydirectory = opendir($directory) or die("Erreur lors de l'ouverture du repertoire");
		while($Entry = @readdir($Mydirectory)) {
			if ($Entry!='.' && $Entry!='..'){
				//$path_tmp = $directory.'/'.$Entry;
				$path_tmp = $Entry;
				array_unshift($pathes,$path_tmp);
			}
		}
	  closedir($Mydirectory);
	  return $pathes;
	}


}


?>